package com.tjdr.his.domain.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.github.yulichang.base.MPJBaseMapper;
import com.tjdr.his.domain.entity.Register;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface IRegisterMapper extends MPJBaseMapper<Register> {

    @Select({"<script>" +
            "select * from register r where r.id in (select DISTINCT p.register_id  from prescription p  where p.drug_state = #{drugState})" +
            "and r.real_name like '%${realName}%'"+
            "<if test='caseNumber != null'>and case_number=#{caseNumber}</if>"+
            " limit ${begin},${size}"+
            "</script>"})
    List<Register> selectRegisterAndPrescrptionInfo( @Param("begin") int begin , @Param("size")  int size, @Param("realName") String realName,@Param("caseNumber") String caseNumber,@Param("drugState") String drugState);

    @Select({"<script>" +
            "select count(*) from register r where r.id in (select DISTINCT p.register_id  from prescription p  where p.drug_state = #{drugState})" +
            "and r.real_name like '%${realName}%'"+
            "<if test='caseNumber != null'>and case_number=#{caseNumber}</if>"+
            "</script>"})
    int selectRegisterAndPrescrptionInfoCount(@Param("realName") String realName,@Param("caseNumber") String caseNumber,@Param("drugState") String drugState);
}
